<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/template.xhtml">

	<ui:define name="content">
		<h:form>

			<p:panel id="oppesquisa" display="Opções de Pesquisa">
				<p:panelGrid columns="2">

					<h:outputText value="Data do voo:" />
					<p:calendar id="dataVoo" />

					<h:outputText value="Origem do voo:" />
					<p:selectOneMenu id="origem" value="#{pesquisaController.origem}"
						effect="fade" required="true">
						<f:selectItem itemLabel="Escolha um aeroporto" itemValue="-999" />
						<f:selectItems value="#{vooController.listaAeroportos}"
							var="aeroporto" itemLabel="#{aeroporto.nome}"
							itemValue="#{aeroporto.codigo}" />
					</p:selectOneMenu>

					<h:outputText value="Destino do voo:" />
					<p:selectOneMenu id="origem" value="#{pesquisaController.origem}"
						effect="fade" required="true">
						<f:selectItem itemLabel="Escolha um aeroporto" itemValue="-999" />
						<f:selectItems value="#{vooController.listaAeroportos}"
							var="aeroporto" itemLabel="#{aeroporto.nome}"
							itemValue="#{aeroporto.codigo}" />
					</p:selectOneMenu>
				</p:panelGrid>

				<p:commandButton value="pesquisar" />

			</p:panel>

			<p:panel id="itensPesquisados" display=" Resultado da Pesquisa"	rendered="#{pesquisaController.via}">
				<p:dataTable value="#{pesquisaController.resultadoPesquisa()}" var="voo" paginator="true" rows="10" selection="#{pesquisaController.selectedVooIda}">
					<p:column selectionMode="single" rendered="#{longinController.conta.adm}"></p:column>
					<p:column>
						<h:outputText value="#{voo.codigo}" />
						<f:facet name="header">
							<h:outputText value="Código" />
						</f:facet>
					</p:column>

					<p:column>
						<h:outputText value="#{voo.from.nome}" />
						<f:facet name="header">
							<h:outputText value="De/From" />
						</f:facet>
					</p:column>

					<p:column>
						<h:outputText value="#{voo.to.nome}" />
						<f:facet name="header">
							<h:outputText value="Para/To" />
						</f:facet>
					</p:column>

					<p:column>
						<h:outputText value="#{voo.data}" />
						<f:facet name="header">
							<h:outputText value="Hora da partida" />
						</f:facet>
					</p:column>

					<f:facet name="footer" rendered="#{longinController.conta.adm}">
						<p:commandButton id="viewButton" value="Exibir detalhe do voo"
							icon="ui-icon-search" update="displaySingle"
							oncomplete="PF('exibirVoo').show()" />
					</f:facet>


				</p:dataTable>

			</p:panel>

			<p:dialog id="dialog" header="Detalhe do Voo" widgetVar="exibirVoo"
				resizable="false" showEffect="fade" hideEffect="explode">

				<p:panelGrid columns="2" id="displaySingle">
					<h:outputText value="Codigo do Voo:" />
					<h:outputText value="#{vooController.voo.codigo}" />

					<h:outputText value="Aeroporto de Origem:" />
					<h:outputText value="#{vooController.voo.from}" />

					<h:outputText value="Aeroporto de Destino:" />
					<h:outputText value="#{vooController.voo.from}" />

					<h:outputText value="Data de partida:" />
					<h:outputText value="#{vooController.voo.dataFinal}" />

					<h:outputText value="Avião:" />
					<h:outputText value="#{vooController.voo.aviao.modelo}" />

					<h:outputText value="Quantida máxima de passageiros:" />
					<h:outputText value="#{vooController.voo.aviao.capacidade}" />

					<h:outputText value="Duração:" />
					<h:outputText value="#{vooController.voo.duracao}" />
					
						<p:dataTable value="#{vooController.getPassageiros}"
						var="passageiro">
						<h:column>
							<h:outputText value="#{userController.user.id}" />
							<f:facet name="header">
								<h:outputText value="Código do passageiro" />
							</f:facet>
						</h:column>

						<h:column>
							<h:outputText value="#{userController.user.nome}" />
							<f:facet name="header">
								<h:outputText value="Nome do passageiro" />
							</f:facet>
						</h:column>
					</p:dataTable>
				</p:panelGrid>
			</p:dialog>

		</h:form>

	</ui:define>
</ui:composition>
</html>